/**
 * 数值类型字符串千分位处理
 * @param string 数值类型字符串
 * @param decimalPlaces 小数位数，范围0-20，
 * 0为无小数位数并进行四舍五入，若该参数不传为与原数保持一致
 * @return {string}
 */
export var numberFormat = function numberFormat(str, options) {
  var _window, _navigator$language, _decimalPlaces, _decimalPlaces2;
  var decimalPlaces = options === null || options === void 0 ? void 0 : options.decimalPlaces;
  var navigator = (_window = window) === null || _window === void 0 ? void 0 : _window.navigator;
  var isSupported = Boolean(navigator && 'language' in navigator);
  if (!isSupported) throw new Error('The environment does not support transformation');
  var fractionDigits = 0;
  if (str.indexOf('.') !== -1) {
    fractionDigits = str.split('').slice(str.indexOf('.') + 1, str.split('').length).length;
  }
  if (typeof decimalPlaces !== 'number' || decimalPlaces < 0 || decimalPlaces > 20) decimalPlaces = undefined;
  return new Intl.NumberFormat((_navigator$language = navigator === null || navigator === void 0 ? void 0 : navigator.language) !== null && _navigator$language !== void 0 ? _navigator$language : 'zh-CN', {
    minimumFractionDigits: (_decimalPlaces = decimalPlaces) !== null && _decimalPlaces !== void 0 ? _decimalPlaces : fractionDigits,
    maximumFractionDigits: (_decimalPlaces2 = decimalPlaces) !== null && _decimalPlaces2 !== void 0 ? _decimalPlaces2 : fractionDigits
  }).format(Number(str));
};

/**
 * 数值类型字符串去除单位
 * @param string 数值类型字符串
 * @return {number}
 */
export var removeUnit = function removeUnit(str) {
  var isExtracted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  // const reg = /^[\d]+[.\da-zA-Z]*[a-zA-Z\u4e00-\u9fa5]$/;
  // if (!reg.test(str)) throw;
  return isExtracted ? {
    value: Number(str.replace(/[\u4e00-\u9fa5a-zA-Z]/g, '')),
    unit: str.replace(/[^a-zA-Z\u4e00-\u9fa5]/g, '')
  } : Number(str.replace(/[\u4e00-\u9fa5a-zA-Z]/g, ''));
};